use fltk::{
    frame::Frame,
    enums::{FrameType, Color},
    prelude::*,
};
use crate::common::event::AppEvent;

// 颜色常量
const COLOR_SYSTEM_BG: Color = Color::from_rgb(240, 240, 240);  // 系统界面背景色

pub struct RightPanel {
    _app_width: i32,    // app width
    _app_height: i32,   // app height
    _start_x: i32,      // position x of the panel
    _start_y: i32,      // position y of the panel
    _width: i32,        // width of the panel
    _height: i32,       // height of the panel
}

impl RightPanel {
    pub fn new(app_width: i32, app_height: i32, start_x: i32, start_y: i32) -> Self {
        let (w, h) = Self::draw_area_size(app_width, app_height, start_x, start_y);

        let mut frame = Frame::new(start_x, start_y, w, h, "");
        frame.set_frame(FrameType::EngravedBox);
        frame.set_color(COLOR_SYSTEM_BG);

        Self {
            _app_width:     app_width,
            _app_height:    app_height,
            _start_x:       start_x,
            _start_y:       start_y,
            _width:         w,
            _height:        h,
        }
    }

    fn draw_area_size(app_width: i32, app_height: i32, sx: i32, _sy: i32) -> (i32, i32) {
        let w = app_width - sx;
        let h = app_height / 3 * 2;  // the same as center panel
        (w, h)
    }

    pub fn get_coordinates(&self) -> (i32, i32, i32, i32) {
        (self._start_x, self._start_y, self._start_x + self._width, self._start_y + self._height)
    }

    pub fn handle_event(&mut self, event: &AppEvent) {
        println!("RightPanel handleEvent {:?}", event);
    }
}
